javascript:(function(){
	function unframe() {
		if (document.getElementsByName('mafiawars')[0]) {
			window.location.href=document.getElementsByName('mafiawars')[0].src;
			return;
		}
		else if (document.getElementsByClassName('canvas_iframe_util')[0]) {
			window.location.href=document.getElementsByClassName('canvas_iframe_util')[0].src;
			return;
		}
		else {
			document.body.parentNode.style.overflowY="scroll";
			document.body.style.overflowX="auto";
			document.body.style.overflowY="auto";
			try {
				document.evaluate('//div[@id="mw_city_wrapper"]/div',document,null,XPathResult.ORDERED_NODE_SNAPSHOT_TYPE,null).snapshotItem(0).style.margin="auto";
				if(typeof FB != 'undefined') {
					FB.CanvasClient.stopTimerToSizeToContent; 
					window.clearInterval(FB.CanvasClient._timer);
					FB.CanvasClient._timer=-1;
				}
				document.getElementById('mw_zbar').parentNode.removeChild(document.getElementById('mw_zbar'));
			}
			catch (fberr) {}
		}
	}
	unframe();

	var version = 'Re-Vaulter v1.04 beta',
	content = document.getElementById('content_row'),
	userid = /sf_xw_user_id=([a-z]\|[0-9]+)/.exec(document.body.innerHTML)[1],
	personid = /([a-z]\|([0-9]+))/.exec(userid)[2],
	buttons = document.getElementsByClassName('sexy_button'),
	vault_ids = [],
	vault_names = [],
	combinedloot = '',
	vault_id = 0,
	city,
	repeat = 0,
	repeats = parseInt(prompt(version+'\nEnter number of times to repeat the vaulting:'));

	var running_html = 
	'<style type="text/css">'+
		'.messages img{margin:0 3px;vertical-align:top}'+
		'#close{display:inline}'+
	'</style>'+
	'<table class="messages">'+
	'<tr>'+
		'<td></td><td colspan="2" align="right" style="text-align:right;font-size:1.1em;">'+version+' - <a href="http://www.spockholm.com/mafia/bookmarklets.php" target="_top">Spockholm Mafia Tools</a> - <a href="http://www.spockholm.com/mafia/donate.php?ReVaulter" id="donate" alt="Donate a Pint" target="_blank">Donate</a> - <a href="#" id="close"><img src="http://www.spockholm.com/mafia/stop.gif" title="Close" alt="Close" width="16" height="16"></a></td></tr>'+
	'</tr>'+
	'<tr>'+
		'<td width="100">Progress:</td>'+
		'<td colspan="2"><span id="repeats"></span></td>'+
	'</tr>'+
	'<tr>'+
		'<td>Status:</td>'+
		'<td colspan="2"><span id="status"></span></td>'+
	'</tr>'+
	'<tr>'+
		'<td valign="top"><a href="#" id="lootshow">Showing</a> Loot:</td>'+
		'<td colspan="2" id="loot" valign="top"></td>'+
	'</tr>'+
	'<tr>'+
		'<td valign="top"><a href="#" id="logshow">Showing</a> Log:</td>'+
		'<td colspan="2" id="log" valign="top"></td>'+
	'</tr>'+
	'</table>';
	
	for (i=0;i<buttons.length;i++) {
		if (id=/vault_id=(\d+).*?selected_city=(\d+)/.exec(buttons[i].href)) {
			vault_ids.push(id[1]);
			city = id[2];
		}
	}
	
	function vaultNext() {
		if (vault_ids.length > 0) { //there are ids in the vault_ids array to process
			if (vault_id < vault_ids.length) { //we have not reached the end
				vaultCollection(vault_ids[vault_id],city);
			}
			else { //we have reached the end (and are doomed..... j/k)
				repeat++;
				if (repeat == repeats) { //we have reached the number of repeats
					msg('<span class="good">Revaulting '+repeats+' time(s), complete.</span>');
					log('Revaulting '+repeats+' time(s), complete.');
				}
				else { //still more repeats to go, start from the beginning again
					vault_id = 0;
					vaultCollection(vault_ids[vault_id],city);
				}
			}
		}
		else {
			msg('<span class="bad">Ran out of items before all repeats were done.</span>');
			log('Ran out of items before all repeats were done.');
		}
	}
	
	function unix_timestamp() {
		return parseInt(new Date().getTime().toString().substring(0, 10))
	}
	function myRandom(min,max) {
		return min +  Math.floor(Math.round((Math.random() * (max - min))));
	}
	
	function create_div() {
		if (document.getElementById('spockdiv')) {
			document.getElementById('spockdiv').innerHTML = running_html;
		}
		else {
			var spock_div = document.createElement("div");
			spock_div.id = 'spockdiv';
			spock_div.innerHTML = running_html;
			content.insertBefore(spock_div, content.firstChild);
		}
		
		document.getElementById('close').onclick=function() {
			document.getElementById("content_row").removeChild(document.getElementById("spockdiv"));
			return false;
		};
		
		document.getElementById('logshow').onclick=function(e) {
			var row = document.getElementById('log');
			if (row.style.display == '') { 
				row.style.display = 'none'; 
				document.getElementById('logshow').innerHTML = 'Hiding';
			}
			else { 
				row.style.display = '';
				document.getElementById('logshow').innerHTML = 'Showing';
			}
			return false;
		};
		
		document.getElementById('lootshow').onclick=function(e) {
			var row = document.getElementById('loot');
			if (row.style.display == '') { 
				row.style.display = 'none'; 
				document.getElementById('lootshow').innerHTML = 'Hiding';
			}
			else { 
				row.style.display = '';
				document.getElementById('lootshow').innerHTML = 'Showing';
			}
			return false;
		};
	}
	
	function vaultCollection(id,city) {
		var cb = userid+unix_timestamp();
		var params = {
			"xw_city": city,
			"tmp": "",
			"cb": cb,
			"xw_person": personid,	
			"xw_client_id": 8,
			"ajax": 1, 
			"liteload": 1,
			"sf_xw_sig": local_xw_sig,
			"sf_xw_user_id": userid,
			"vault_id": id,
			"selected_city": city
		};
		
		$.ajax({
			type: 'POST',
			url: 'http://facebook.mafiawars.com/mwfb/remote/html_server.php?xw_controller=collection&xw_action=vault',
			data: params,
			success: function (response) {
				try {
					if (vaulted=/You successfully (re)?vaulted the (.*?) set and gained: ((\d+)? )(.*?)\((.*?)\)/.exec(response)) {
						add_loot(vaulted[5],parseInt(vaulted[4]),vaulted[6]);
						vault_names[id] = vaulted[2];
						log('Gained: '+vaulted[4]+'x '+vaulted[5]+' <span class="more_in">('+vaulted[6]+')</span>');
						vault_id++;
					}
					if (/have the required items to vault/.test(response)) {
						log('<span class="bad">Not enough items to vault collection id: '+id+' name: '+(vault_names[id] == 'undefined'?vault_names[id]:'Unknown')+'</span>');
						vault_ids.splice(vault_ids.indexOf(id),1);
					}
					msg('Vaulting next item...');
					setTimeout(function(){ vaultNext(); },4000);
					//alert(combinedloot);
				}
				catch (problem) { 
					log('<span class="bad">Error in vaultCollection():</span> '+problem);
				}
			}
		});
	}
	function timestamp() {
		now = new Date();
		var CurH = now.getHours();
		CurH = (CurH<10?"0"+CurH:CurH);
		var CurM = now.getMinutes();
		CurM = (CurM<10?"0"+CurM:CurM);
		return '<span class="more_in">['+CurH+':'+CurM+']</span> ';
	}
	function msg(s) {
		document.getElementById('status').innerHTML = s;
	}
	function log(text) {
		document.getElementById('donate').style.color = (repeat%3==1?'#E00000':'');
		document.getElementById('repeats').innerHTML = 'Repeat: '+repeat+' of '+repeats+' &nbsp;-&nbsp; Item: '+vault_id+' of '+vault_ids.length;
		var l = document.getElementById('log').innerHTML;
		document.getElementById('log').innerHTML = l+'<br />'+timestamp()+text;
		document.getElementById('loot').innerHTML = combinedloot;
	}
	
	var loots = [];
	function add_loot(item,count,description) {
		var f = -1;
		for (var i = 0; i < loots.length && f == -1; ++i) { //search for the item
			if (loots[i][0] == item) {
				f = i;
			}
		}
		if (count == null || count == undefined) { count = 1; }
		if (f != -1) { //item already in array
			loots[f][1] += count;
		}
		else { //item not in array, make new entry
			loots[loots.length] = new Array(item,count,description);
		}
		var t = '';
		loots.sort();
		for (var i = 0; i < loots.length; ++i) {
			t += '<span class="good">'+loots[i][1]+'x</span> '+loots[i][0]+' <span class="more_in">('+loots[i][2]+')</span><br />';
		}
		combinedloot = t;
		return false;
	}
	
	//start the process
	if (repeats > 0) {
		create_div();
		vaultNext();
	}
	else {
		alert('Faulty number of repeats entered.');
	}

})()